import nodemailer from "nodemailer";

const transporter = nodemailer.createTransport({
    host: process.env.EMAIL_HOST,
    port: Number(process.env.EMAIL_PORT),
    secure: true,
    auth: {
      user: process.env.EMAIL,
      pass: process.env.EMAIL_PASSWORD,
    },
  }),
  /**
   * 发送邮件
   * @param { Object } data 邮件配置
   * @returns {Promise}
   */
  sendMail = (data) => {
    return new Promise((resolve, reject) => {
      transporter.sendMail(data, (err, info) => {
        if (err) reject(err);
        else resolve(info);
      });
    });
  };

export default sendMail;
